#ifndef CAVE_H
#define CAVE_H

#include "Demo.h"
#include "VectorBatch.h"
#include "Mesh.h"
#include "Camera.h"

using namespace Cvekas;

class Cave : public TimelineSegment
{
public:
	Cave(RendererPtr renderer, VectorBatchPtr vector_batch);
	virtual ~Cave();

	virtual void init(boost::weak_ptr<Demo> owner);
	virtual void close();
	
	virtual void update(float t);
	virtual void render(float t);
	
protected:
	float cube_size;
	float cube_size_ratio;
	float cube_distance;
	float cube_distance_ratio;
	Vector3 cube_rotation;
	Vector3 cube_rotation_delta;

	uint cube_idx;
	void cubeFractal(const Vector3& pos, float cube_size, float cube_size_ratio, float cube_distance, 
		float cube_distance_ratio, const Vector3& cube_rotation, const Vector3& cube_rotation_delta, int depth);

private:
	
	static const int cube_depth = 4;
	static const int cube_count = 1 + 6 + 6 * 6 + 6 * 6 * 6;

	VectorBatchPtr vector_batch;
	RendererPtr renderer;
	RenderableMeshPtr cave;
	RenderableMeshPtr cubes[cube_count];

	EffectPtr cube_effect;
	ParamHandle cubes_texture;
	ParamHandle cubes_light_pos;
	ParamHandle cubes_light_color;
	ParamHandle cubes_light_attenuation;

	Vector3 light_pos;
	Vector3 light_color;
	float light_attenuation;

	std::vector<Vector2> fullscreen_rect;

	SimpleCamera camera;
};

typedef boost::shared_ptr<Cave> CavePtr;

#endif